home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1244
/
procapp2.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-17
|
6KB
|
240 lines
#include <windows.h>
#include "procbox.h"
HINSTANCE hinst;
int CALLBACK _export PBCallback1(HWND, int , LPARAM);
int CALLBACK _export PBCallback2(HWND, int , LPARAM);
////////////////////////////////////////////////////////////////////////////////
//
// PROCAPP2.C - Demonstrates use of ProcessBox Multiple Callback Interface
//
// - Contains code for
// - WinMain Entry Point
// - WndProc
LRESULT FAR PASCAL _export WndProc(HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "PROCAPP2";
char szWindowText[] = "ProcessBox - Multiple Callback Modal Interface Demo";
/////////////////////////////////////////////////
//
//
// WndProc
//
LRESULT FAR PASCAL _export WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
FARPROC lpfnPBCallback;
char szText[64];
HWND hwndPB;
switch (message)
{
case WM_KEYDOWN:
case WM_LBUTTONDOWN:
hwndPB = CreateProcessBox( hwnd, // owner
NULL, // caption
"Callback 1 in process...", // message
10,50, // x,y screen coords of box
PB_MESSAGE);
if (hwndPB==NULL)
return 0;
////////////////////////
//
// FIRST CALLBACK:
//
lpfnPBCallback = MakeProcInstance((FARPROC)PBCallback1, hinst);
if (AttachProcess(hwndPB, lpfnPBCallback, NULL)==PBE_OK)
{
wsprintf(szText, "Returned: %d",
RunProcess(hwndPB)); // returns after process is done
MessageBox(hwnd, szText, NULL, NULL);
}
else
MessageBox(hwnd, "Failed to attach process!", NULL,NULL);
AttachProcess(hwndPB, NULL, NULL); // detach the process BEFORE freeing it!
FreeProcInstance(lpfnPBCallback);
////////////////////////
//
// SECOND CALLBACK:
//
lpfnPBCallback = MakeProcInstance((FARPROC)PBCallback2, hinst);
if (AttachProcess(hwndPB, lpfnPBCallback, NULL)==PBE_OK)
{
wsprintf(szText, "Returned: %d",
RunProcess(hwndPB)); // returns after process is done
MessageBox(hwnd, szText, NULL, NULL);
}
else
MessageBox(hwnd, "Failed to attach process!", NULL,NULL);
DestroyProcessBox(hwndPB); // DestroyProcessBox BEFORE freeing the proc-instance!!
FreeProcInstance(lpfnPBCallback);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam );
}
///////////////////////////////////////////////////////////
//
// Process Box Callback 1
//
//
int CALLBACK _export PBCallback1(HWND hwndPB, int iCode, LPARAM lParam)
{
static i;
long j;
switch (iCode)
{
case PBC_OPEN:
// allocate memory here
i=0;
return TRUE;
case PBC_CLOSE:
// free memory here
return TRUE;
case PBC_CANCEL:
return ( MessageBox(hwndPB, "Really cancel operation?", "Message Box",
MB_APPLMODAL|MB_YESNO)==IDYES ? TRUE : FALSE );
case PBC_PROCESS:
i++;
if (i==5000)
{
SendMessage(hwndPB, PM_SETMESSAGE, 0, (LPARAM)(LPSTR)"Callback 1\nReached halfway");
}
for (j=0; j<0xEFF; j++); // a delay
if (i>10000)
return PBCR_END;
SendMessage(hwndPB, PM_SETGAUGE, i/100, 0l);
return PBCR_CONTINUE;
}
return TRUE;
}
///////////////////////////////////////////////////////////
//
// Process Box Callback 2
//
//
int CALLBACK _export PBCallback2(HWND hwndPB, int iCode, LPARAM lParam)
{
static i;
long j;
switch (iCode)
{
case PBC_OPEN:
// allocate memory here
i=0;
return TRUE;
case PBC_CLOSE:
// free memory here
return TRUE;
case PBC_CANCEL:
return ( MessageBox(hwndPB, "Really cancel operation?", "Message Box",
MB_APPLMODAL|MB_YESNO)==IDYES ? TRUE : FALSE );
case PBC_PROCESS:
i++;
if (i==1)
{
SendMessage(hwndPB, PM_SETMESSAGE, 0, (LPARAM)(LPSTR)"Second callback\nGoes faster!");
}
for (j=0; j<0xFF; j++); // a delay
if (i>10000)
return PBCR_END;
SendMessage(hwndPB, PM_SETGAUGE, i/100, 0l);
return PBCR_CONTINUE;
}
return TRUE;
}
/////////////////////////////////////////////////
//
//
// WinMain - Entry Point
//
//
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG msg ;
WNDCLASS wndclass ;
HWND hwnd;
hinst = hInstance;
if (!hPrevInstance)
{
wndclass.style = NULL ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow ( szAppName, // class
szWindowText, // window text
WS_OVERLAPPEDWINDOW, // style
CW_USEDEFAULT, CW_USEDEFAULT, // x, y start
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
NULL, // parent window handle
NULL, // menu handle
hInstance, // instance handle
NULL) ; // long pointer to creation data
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}